﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lawyer.Model;
using Lawyer.BLL;
namespace Lawyer.Web.Admin
{
    public partial class admin_useradd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
 
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.txbUserName.Text == "") {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "The enter is not valid！", "admin_useradd.aspx");
                return;
            }
            if (this.txbPassConf.Text != this.txbPassword.Text)
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "Password not match！", "admin_useradd.aspx");
                return;
            }

            Lawyer.Model.UserInfo user = CreateFromForm();
            Lawyer.BLL.UserInfo bll = new Lawyer.BLL.UserInfo();
            bll.Add(user);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "success！", "admin_userlist.aspx");

        }
        private Lawyer.Model.UserInfo CreateFromForm()
        {
			string UserName=this.txbUserName.Text;
			string Password=this.txbPassword.Text;
			string FullName=this.txbFullName.Text;
			string Email=this.txbEmail.Text;
            string Sex = this.rblGender.SelectedValue;
			DateTime Birthday=DateTime.Parse(this.txbBirthday.Text);
			string City=this.txtCity.Text;
			string Telphone=this.txtTelphone.Text;
			string Fax=this.txtFax.Text;
			string Address=this.txtAddress.Text;
			string AvatarURL=this.txtAvatarURL.Text;


			Lawyer.Model.UserInfo model=new Lawyer.Model.UserInfo();
			model.UserName=UserName;
			model.Password=Password;
			model.FullName=FullName;
			model.Email=Email;
			model.Sex=Sex;
			model.Birthday=Birthday;
			model.City=City;
			model.Telphone=Telphone;
			model.Fax=Fax;
			model.Address=Address;
			model.AvatarURL=AvatarURL;

            model.UserID = Guid.NewGuid().ToString();
            model.CreatedBy = Session["UserID"].ToString(); ;
            model.CreatedDate = DateTime.Now;
            model.Status = 0;//0=>Normal,1=>Deleted
            //model.Type = 2;//2=>Lawyer,1=>admin
            model.Type = Int32.Parse(cblType.SelectedValue);
            model.UpdatedBy = Session["UserID"].ToString(); ;
            model.UpdatedDate = DateTime.Now;
            return model;

        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            Response.Redirect("admin_userlist.aspx");
        }
    }
}
